# -*- coding: utf-8 -*-
import xadmin

from .models import *
from .forms import *
from .resources import *


class BarCodeAdmin(object):
    hidden_menu = True
    all_fields = [field.name for field in BarCode._meta.fields]
    list_display = all_fields
    form = BarCodeForm


class LabelTargetAdmin(object):
    all_fields = [field.name for field in LabelTarget._meta.fields]
    list_display = all_fields
    search_fields = ["code", "target"]
    list_editable = ['code', 'target']

    class LabelSeriesInline(object):
        model = LabelSeries
        # exclude = ['', ]
        extra = 1
        style = 'tab'
    inlines = [LabelSeriesInline, ]


class LabelSeriesAdmin(object):
    all_fields = [field.name for field in LabelSeries._meta.fields]
    list_filter = ["fk_target"]
    search_fields = ["code", "title"]
    list_display = all_fields
    show_detail_fields = ['fk_target']
    list_editable = ['fk_target', 'code', 'title']
    # list_display_links = ['id']

    class LabelInline(object):
        model = Label
        # exclude = ['', ]
        extra = 1
        style = 'tab'
    inlines = [LabelInline, ]


class LabelAdmin(object):
    all_fields = [field.name for field in Label._meta.fields]
    search_fields = ["code", "title"]
    list_filter = ["fk_series"]
    list_display = all_fields
    show_detail_fields = ['fk_series']
    list_editable = ['code','title','fk_series']
    # list_display_links = ['id']
    import_export_args = {'import_resource_class': LabelResource,
                          'export_resource_class': LabelResource}
    relfield_style = 'fk-ajax'


class LabelStickGoodAdmin(object):
    all_fields = [field.name for field in LabelStickGood._meta.fields]
    list_filter = ["fk_good", "fk_label"]
    list_display = all_fields
    show_detail_fields = ["fk_good", "fk_label"]
    list_editable = ["fk_good", "fk_label"]
    form = LabelStickGoodForm
    import_export_args = {'import_resource_class': LabelStickGoodResource,
                          'export_resource_class': LabelStickGoodResource}
    relfield_style = 'fk-ajax'


xadmin.site.register(BarCode, BarCodeAdmin)
xadmin.site.register(Label, LabelAdmin)
xadmin.site.register(LabelStickGood, LabelStickGoodAdmin)
xadmin.site.register(LabelSeries,LabelSeriesAdmin)
xadmin.site.register(LabelTarget,LabelTargetAdmin)

